<template>
  <div class="cartcontrol">
    <transition name="move">
      <div class="cart-decrease icon-remove_circle_outline" v-show="food.count>0" @click="decreaseCart"></div>
    </transition>
    <div class="cart-count" v-show="food.count>0">{{food.count}}</div>
    <div class="cart-add icon-add_circle" @click="addCart($event)"></div>
  </div>
</template>

<script>
export default {
  props: {
    food: {
      type: Object
    }
  },
  methods: {
    addCart(e) {
      if (!this.food.count) {
        this.$set(this.food, 'count', 1)
      } else {
        this.food.count++
      }
      this.$emit('add', e.target)
    },
    decreaseCart() {
      if (this.food.count > 0) {
        this.food.count--
      }
    }
  },
  created() {
    // console.log(this.food)
  }
}
</script>

<style lang='stylus'>
  .cartcontrol
    font-size 0
    .move-enter-active, .move-leave-active
      transition all .4s linear
    .move-enter, .move-leave-to
        opacity 0
        -webkit-transform translate3d(24px, 0, 0) rotate(180deg)
        transform  translate3d(24px, 0, 0)  rotate(180deg)
    .cart-decrease, .cart-add
      display inline-block
      padding 6px
      line-height 24px
      font-size 24px
      color rgb(0,160,220)
    .cart-count
      display inline-block
      vertical-align top
      width 12px
      padding-top 6px
      line-height 24px
      text-align center
      font-size 10px
      color rgb(147,153,159)
    .cart-add
      display inline-block
</style>
